from flask import Flask, request, jsonify
import sqlite3

app = Flask(__name__)

@app.route('/api/data')
def get_data():
    page = int(request.args.get('page', 1))
    size = int(request.args.get('size', 10))

    # 连接数据库
    conn = sqlite3.connect('example.db')
    cursor = conn.cursor()

    # 计算偏移量
    offset = (page - 1) * size

    # 执行查询语句
    cursor.execute("SELECT * FROM users LIMIT ? OFFSET ?", (size, offset))
    data = cursor.fetchall()

    # 关闭数据库连接
    cursor.close()
    conn.close()

    # 返回当前页数据
    return jsonify(data)

if __name__ == '__main__':
    app.run()
